package com.example.demo.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.Category;
import com.example.demo.service.ICategoryService;
import com.example.demo.service.impl.ICategoryServiceImpl;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

//表明当前类是一个控制层，并交给ioc控制
@RestController
@RequestMapping("/category")
public class ICategoryController {
	
	
	//给引用属性赋值
	@Resource
	private ICategoryService is;
	

	@RequestMapping("/save")
	public String save1(Category cg1) {

		is.save(cg1);
	
		return "保存成功";
		
	}
	
	@ApiOperation("查询所有栏目信息")
	@GetMapping("/findAll")
	public List<Category> findAll(){
		
	return	is.findAll();
	}
	
	@ApiOperation("根据id查询所有信息")
	@ApiImplicitParam(name="id",value="栏目id",required=true,dataType="long")
	@GetMapping("/findById")
	public Category findBId(Long id) {
		return is.findById(id);
	}
	
	
	
	@ApiOperation("根据name 删除信息")
	@GetMapping("/deleteByName")
	@ApiImplicitParam(name="name",value="栏目name",required=true,dataType="String")
	public String deleteCategory(String name) {
		is.delteCategory(name);
		return "删除成功";
	}

	
	@ApiOperation("更新栏目信息")
	@GetMapping("/updageCategory")
	public String changeCategory(String name,Long id) {
		is.changeCategory(name, id);
		return "更新成功了";
	}
}
